package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.getInteractionStateBean;
import com.ymatou.iapi.godmch.parameter.setInteractionStateBean;
import com.ymatou.iapi.godmch.service.getInteractionStateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.interactionstate;
import com.ymttest.database.model.godmch.interactionstateExample;
import com.ymttest.database.sqlwapper.godmch.interactionstateWapper;
/**
*获取前端交互状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getInteractionState{
	private static getInteractionStateBean bean;
	private static getInteractionStateCall call;
	private  interactionstateExample interactionstateExample=new interactionstateExample();
	private  interactionstateWapper interactionstateWapper=new interactionstateWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取前端交互状态");
	}

	@Before
	public void caseUp() {
		bean=new getInteractionStateBean();
		call=new getInteractionStateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getInteractionState_001() {
		Logger.start(true,"正例-获取前端交互状态-返回成功");
		try {
			//创建渠道
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setInteractionStateBean setInteractionStateBean=GodmchManageCallService.SetInteractionState(mchId);
			bean.setMchId(mchId);
			bean.setBizKey(setInteractionStateBean.getBizKey());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        interactionstateExample.clear();
	        interactionstateExample.createCriteria().andBizKeyEqualTo(bean.getBizKey()).andMchIdEqualTo(bean.getMchId());
	        interactionstate model=interactionstateWapper.selectByExample(interactionstateExample).get(0);
	        
	        Logger.verifyEquals(call.getMchId(), model.getMchId(), "验证MchId");
	        Logger.verifyEquals(call.getBizKey(), model.getBizKey(), "验证BizKey");
	        Logger.verifyEquals(model.getBizValues(), model.getBizValues(), "验证BizValues");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getInteractionState_002() {
		Logger.start(true,"正例-获取前端交互状态-BizKey不存在-返回BizValues为空");
		try {
			//创建渠道
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setInteractionStateBean setInteractionStateBean=GodmchManageCallService.SetInteractionState(mchId);
			bean.setMchId(mchId);
			bean.setBizKey(setInteractionStateBean.getBizKey()+99999);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        
	        Logger.verifyEquals(bean.getMchId(), call.getMchId(), "验证MchId");
	        Logger.verifyEquals(bean.getBizKey(), call.getBizKey(), "验证BizKey");
	        Logger.verifyEquals("",call.getBizValue(), "验证BizValues");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getInteractionState_003() {
		Logger.start(true,"正例-获取前端交互状态-mch不存在-返回BizValues为空");
		try {
			//创建渠道
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setInteractionStateBean setInteractionStateBean=GodmchManageCallService.SetInteractionState(mchId);
			bean.setMchId(mchId+999999);
			bean.setBizKey(setInteractionStateBean.getBizKey());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
      
	        Logger.verifyEquals(bean.getMchId(), call.getMchId(), "验证MchId");
	        Logger.verifyEquals(bean.getBizKey(), call.getBizKey(), "验证BizKey");
	        Logger.verifyEquals("",call.getBizValue(), "验证BizValues");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getInteractionState_004() {
		Logger.start(true,"正例-获取前端交互状态-mchId为空-返回失败");
		try {
			//创建渠道
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setInteractionStateBean setInteractionStateBean=GodmchManageCallService.SetInteractionState(mchId);
			//bean.setMchId(mchId);
			bean.setBizKey(setInteractionStateBean.getBizKey()+99999);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getInteractionState_005() {
		Logger.start(true,"正例-获取前端交互状态-BizKey为空-返回失败");
		try {
			//创建渠道
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			setInteractionStateBean setInteractionStateBean=GodmchManageCallService.SetInteractionState(mchId);
			bean.setMchId(mchId);
			//bean.setBizKey(setInteractionStateBean.getBizKey()+99999);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证返回成功status值");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}